package org.example.t03;

public class Disorder {
    static int a = 0,b = 0,x = 0,y = 0;

    public static void main(String[] args) throws InterruptedException {
        int i = 0;
        while (true) {
            a = 0;
            b = 0;
            x = 0;
            y = 0;
            Thread thread1 = new Thread(() -> {
                a = 1;
                x = b;
            });
            Thread thread2 = new Thread(() -> {
                b = 1;
                y = a;
            });
            thread1.start();
            thread2.start();
            i++;
            thread1.join();
            thread2.join();
            if (x == 0 && y == 0){
                System.out.println(i + "次发生了指令重排序");
                break;
            }
        }
    }
}
